package com.itheima.多线程.基础;

public class MaiPiaoDemo implements Runnable{
    //1.规定票数总量与3对应
    private static int count=100;
//    private static final Object object=new Object();
    private static final Object object="";
    @Override
    public void run() {
        //2.窗口一直在卖票
        while (true) {
            synchronized (object) {
                if (count>0) {
                    count--;
                    System.out.println(Thread.currentThread().getName()+"再卖票,还剩"+count);
                } else {
                    break;
                }
            }
        }
    }
}


class Test{
    public static void main(String[] args) {
        //3.100只能在同一个任务类中
        MaiPiaoDemo mp=new MaiPiaoDemo();
        Thread t1=new Thread(mp,"窗口一");
        Thread t2=new Thread(mp,"窗口二");
        Thread t3=new Thread(mp,"窗口三");
        //4.开启线程
        t1.start();
        t2.start();
        t3.start();




    }
}